package liming.tool.maven.tool;

import liming.tool.maven.info.Project;

import java.io.IOException;

public class MavenTool {
    public static String clean(Project project) throws IOException, InterruptedException {
        return build(project,MavenType.CLEAN);
    }
    public static String install(Project project) throws IOException, InterruptedException {
        return build(project,MavenType.INSTALL);
    }
    public static String build(Project project,MavenType... type) throws IOException, InterruptedException {
        String installCmd=String.format("%s\\bin\\mvn.cmd -f \"%s\\pom.xml\" -s \"%s\" %s -Djava.home=\"%s\""
                ,project.getMavenHome()
                ,project.getProjectPath()
                ,project.getMavenSettingPath()
                ,types(type)
                ,project.getJavaHome());
        return CmdTool.run(installCmd);
    }
    private static String types(MavenType... type){
        StringBuilder sb=new StringBuilder();
        for (MavenType s : type) {
            sb.append(" ").append(s.getType());
        }
        return sb.toString();
    }
    public enum MavenType{
        CLEAN("clean"),
        VALIDATE("validate"),
        COMPILE("compile"),
        TEST("test"),
        PACKAGE("package"),
        VERIFY("verify"),
        INSTALL("install"),
        SITE("site"),
        DEPLOY("deploy");
        private final String type;
        MavenType(String type) {
            this.type = type;
        }
        public String getType() {
            return type;
        }
    }
}
